//
//  TeamDetailTableViewCell.m
//  InformationFoot
//
//  Created by 魔曦 on 2018/7/16.
//  Copyright © 2018年 MacBook. All rights reserved.
//

#import "TeamDetailTableViewCell.h"

@implementation TeamDetailTableViewCell
- (void)setBattleModel:(MXBattleModel *)battleModel {
    
    _battleModel = battleModel ;
    
    _timeLabel.text = [self timeInterverlToDateStr:battleModel.matchStartTime] ;
    
    _lianduiLabel.text = battleModel.eventNm ;
    
    _scoreLabel.text = [NSString stringWithFormat:@"%ld-%ld",battleModel.homeScore,battleModel.awayScore] ;
    _firstTeamLabel.text = battleModel.homeNm ;
    _secondTeamLabel.text = battleModel.awayNm ;
    
//    if (battleModel.homeNm.length > 5) {
//        _firstTeamLabel.textAlignment = 1 ;
//    } else {
//        _firstTeamLabel.textAlignment = 2 ;
//    }
//    if (battleModel.awayNm.length > 5) {
//        _secondTeamLabel.textAlignment = 1 ;
//    } else {
//        _secondTeamLabel.textAlignment = 0 ;
//    }
    
    switch (battleModel.matchRst) {
        case -1:
            _stateLabel.text = @"负" ;
            _stateLabel.textColor = Color(128, 128, 128, 1);
            _stateLabel.font = fontSize(scaleWithSize(18));
            break;
        case 0:
            _stateLabel.text = @"平" ;
            _stateLabel.textColor = Color(22, 166, 53, 1) ;
            _stateLabel.font = fontSize(scaleWithSize(18));

            break;
        case 1:
            _stateLabel.text = @"胜" ;
            _stateLabel.textColor = Color(214, 18, 19, 1) ;
            _stateLabel.font = fontSize(scaleWithSize(22));
            break;
            
        default:
            break;
    }
    
}


//时间戳转为时间字符串
- (NSString *)timeInterverlToDateStr:(NSString *)timeStr {
    //timeStr时间戳
    NSTimeInterval time=[timeStr doubleValue];//因为时差问题要加8小时 == 28800 sec
    
    NSDate *detaildate=[NSDate dateWithTimeIntervalSince1970:time];
    
    //    NSLog(@"date:%@",[detaildate description]);
    
    //实例化一个NSDateFormatter对象
    
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    
    //设定时间格式,这里可以设置成自己需要的格式yyyy.MM.dd HH:mm
    [dateFormatter setDateFormat:@"yyyy-MM-dd"];
    
    NSString *currentDateStr = [dateFormatter stringFromDate: detaildate];
    
    return currentDateStr;
}


- (void)awakeFromNib {
    [super awakeFromNib];
    _lianduiLabel.font = fontSize(scaleWithSize(12.0f));
    _timeLabel.font = fontSize(scaleWithSize(10.0f));
    _firstTeamLabel.font = fontSize(scaleWithSize(13.0f));
    _secondTeamLabel.font = fontSize(scaleWithSize(13.0f));
    _scoreLabel.font = fontSize(scaleWithSize(12.0f));
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
